'use strict';

angular.module('myApp.hekaadd', ['ngRoute', 'door3.css'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/hekaadd', {
            templateUrl: 'hekaadd/hekaadd.html' + '?' + Math.random(),
            controller: 'HekaAddCtrl',
            css: 'hekaadd/hekaadd.css' + '?' + Math.random()
        });
    }])

    .controller('HekaAddCtrl', ['$scope', '$routeParams', 'Heka', '$location', function ($scope, $routeParams, Heka, $location) {
        // 背景图
        $scope.heka = {};
        $scope.heka.target = "亲爱的朋友";
        $scope.heka.signature = "爱您的我"
        var random = Math.floor(Math.random() * 3 + 1);
		var randomContent = Math.floor(Math.random() * 5 + 1);
        switch (randomContent) {
            case 1:
                $scope.heka.content = "猴年的生活像苦荞一样有内涵，苦尽甘来~";
                break;
            case 2:
                $scope.heka.content = "新年到，祝你生活精彩，天天都有劲！";
                break;
            case 3:
                $scope.heka.content = "猴年每天都美美哒，越来越有韵味~";
                break;
            case 4:
                $scope.heka.content = "劲酒虽好，新年也不要贪杯哦";
                break;
            case 5:
                $scope.heka.content = "新一年，少喝一点为健康";
                break;
        }
        $scope.bgi = "img/monkey" + random + ".png";
        $scope.addHeka = function () {
            Heka.save($scope.heka, function (response) {
                // 统计制作贺卡
                _hmt.push(['_trackEvent', 'AddHeka', '添加贺卡成功']);
                $location.path("/heka/" + response.data.id);
            });
        }
    }]);